Methods and data structures that are parameterized by type are commonly used in implementing software solutions in object-oriented programming languages, including, for example, C++. Typesafe homogeneous containers are implemented in the Standard C++ Library (SL) using the language-provided template mechanism. A homogeneous container has constituent objects of the same data type. A heterogeneous container has objects of different types. For example, a C++ structure is a heterogeneous container. The size and composition of a structure, are determined at compile time, which limits flexibility.
A commonly used approach by which heterogeneous containers are implemented in C++ is via polymorphism and the run-time type identification (RTTI) facility of C++. Classes that derive from a common base class can be stored in a container via base class pointer and then down cast to the dynamic type upon extraction from the container.
This approach has a number of disadvantages. The polymorphism requires that types supported by the container inherit from a common base class, which may be invasive or restrict implementation flexibility. Furthermore, use of the RTTI facility may introduce substantial overhead since the resolution of data types occurs at runtime. In addition the use of RTTI may increase coding complexity, along with costs of testing and maintaining the program.
The present invention may address one or more of the above issues.